Skip to content

feat: add generic for wrapper.find() and wrapper.get() - #1871

Merged
lmiller1990 merged 5 commits into
vuejs:devfrom
standbyoneself:feature/generic-wrapper-find
Jul 12, 2021
Merged

feat: add generic for wrapper.find() and wrapper.get()#1871
lmiller1990 merged 5 commits into
vuejs:devfrom
standbyoneself:feature/generic-wrapper-find

Conversation

@standbyoneself

@standbyoneself standbyoneself commented Jul 7, 2021

Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • [x ] Feature
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change? (check one)

  • Yes
  • [ x] No

If yes, please describe the impact and migration path for existing applications:

The PR fulfills these requirements:

If adding a new feature, the PR's description includes:

  • A convincing reason for adding this feature (to avoid wasting your time, it's best to open a suggestion issue first and wait for approval before working on it)

Other information:

fix: #1870

This feature will allow to target already the need type of the Element e.g. SVGElement, HTMLElement or other

Example:

const input = wrapper.find<HTMLInputElement>('input')
console.log(input.element.value)

@lmiller1990 lmiller1990 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, one comment

Comment thread packages/test-utils/types/test/wrapper.ts
@lmiller1990
lmiller1990 merged commit c2ee13b into vuejs:dev Jul 12, 2021
@alecgibson

Copy link
Copy Markdown

By defaulting to Element rather than HTMLElement this broke all our tests 😢

alecgibson added a commit to reedsy/vue-test-utils that referenced this pull request Jul 23, 2021
The type definitions were updated to allow generic element typing in
vuejs#1871

However, this "loosened" the default type from `HTMLElement` to
`Element. This was actually a breaking change.

For example, consumers may have had this test code:

```ts
wrapper.element.click()
```

But `click()` only exists on `HTMLElement`, not on `Element`, so test
compilation fails.

This change moves the default type back to `HTMLElement`. If we want to
loosen this requirement in the future, it should be considered a
breaking change.
alecgibson added a commit to reedsy/vue-test-utils that referenced this pull request Jul 23, 2021
The type definitions were updated to allow generic element typing in
vuejs#1871

However, this "loosened" the default type from `HTMLElement` to
`Element. This was actually a breaking change.

For example, consumers may have had this test code:

```ts
wrapper.element.click()
```

But `click()` only exists on `HTMLElement`, not on `Element`, so test
compilation fails.

This change moves the default type back to `HTMLElement`. If we want to
loosen this requirement in the future, it should be considered a
breaking change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Typescript error with wrapper.find('select').element.value

3 participants